package com.atguigu02.singleton;

/**
 * ClassName: BankTest
 * Package: com.atguigu01.singleton
 * Description:
 *
 * @Author ZY
 * @Create 17:06
 * @Version 1.0
 */
public class BankTest {
    public static void main(String[] args) {

//        Bank bank1 = new Bank();
//        Bank bank2 = new Bank();

        Bank bank1 = Bank.getInstance();
        Bank bank2 = Bank.getInstance();

        System.out.println(bank1 == bank2);

    }
}

//饿汉式
class Bank{

    //1.类的构造器私有化
    private Bank(){

    }

    //2.在类的内部创建当前类的实例
    //4.次属性必须声明为static的
    private static Bank instance = new Bank();

    //3.提供一个公共的静态方法，返回当前类的实例,必须声明为static
    public static Bank getInstance(){
        return instance;
    }


}
